<?php
$g4_path = '../';
$lib =  "$g4_path/lib.php";
$menu = 7;
require_once ("$g4_path/common.php");
require_once ($lib);
require_once ('../lib/Template_.class.php');

require_once ('./mydesk.lib.php');
require_once('../head.ebvill.php');

$tpl = new Template_();
$tpl->template_dir = './tpl';
$tpl->compile_dir = './tpl/compile';

$user = getDb('g4_member', $userid, 'mb_id');

$year = isset($_GET['year']) ? $_GET['year'] : date('Y');
$month=  isset($_GET['month']) ? $_GET['month'] : date('m');
$time = mktime(0,0,0,$month, 1, $year);
$date = $year.'-'.$month;
$last = $year.'-'.$month.'-'.date('t',$time);

list($totalCount) = mysql_fetch_row(mysql_query("SELECT count(1) FROM book_order WHERE updated BETWEEN '{$date}-01'  AND '{$last}' AND student = {$user['mb_no']}"));


$page = isset($_GET['page']) ?  $_GET['page'] : 1;
$year = '';
$statusArray = array('1'=>'입금대기','2'=>'입금완료','3'=>'배송 중','4'=>'배송 완료','5'=>'신청취소');

$offset = $page - 1;
$res = mysql_query("SELECT * from book_order o, book b WHERE updated BETWEEN '{$date}-01' AND '{$last}' AND o.book = b.no AND o.student = {$user['mb_no']} LIMIT $offset , 15");

$data = array();
$count = $totalCount - $offset * 15;
while($temp  = mysql_fetch_assoc($res) )  {
    $temp['price'] = number_format($temp['price']);
    $temp['count'] = $count--;
    $temp['statusKey'] = $statusArray[$temp['status']];
    $data[] = $temp;
}

set_include_path(get_include_path().PATH_SEPARATOR. '../lib');
$pager = getpager2($totalCount, 15) ;


$_year = array();
for($i = 2008; $i <= date('Y') ; $i++) {
    $_year[] = $i;
}
$yearSelected = array($year => 'selected="selected"');
$_month = array();
for($i =1 ; $i <= 12 ; $i++) {
    $_month[] = $i;
}
$monthSelected = array($month => 'selected="selected"');

$tpl->define('basic',"myBookOrders.html");
$tpl->print_('basic');
